import pymysql
import pandas as pd

###############参数设置区域######################
###取表数据库参数
host1 = "bj-cdb-0ds18k8v.sql.tencentcdb.com"
#host1 = '192.144.179.178'
user1 = "root"
password1 = "Huayuan@2018"
db1 = "zhongtou"
port1 = 63167
table1 = 'final_tag_4'  #lc

###写表数据库参数
table2 = 'result'
#################################################

class MySQLBase:   #实例方法

    def __init__(self):
        self.host = host1
        self.port = port1
        self.user = user1
        self.db = db1
        self.passwd = password1

        # print(self.host)
        # print(self.passwd)


    def connect(self):
        self.conn = pymysql.connect(host=self.host, user=self.user, passwd=self.passwd, db=self.db, port = self.port)
        self.cur = self.conn.cursor()
        # print(self.conn)

    def query(self, command):
        self.cur.execute(command)
        return self.cur.fetchall()

    def insert(self, command):
        self.cur.execute(command)
        self.conn.commit()

    def execute(self,command):
        self.cur.execute(command)

    def __del__(self):
        self.conn.close()


if __name__ == '__main__':
    mysql = MySQLBase()
    mysql.connect()
    print(mysql.query("select * from final_tag_4"))
